
/* This is the Vehicle class, this is where all attributes for the array of Vehicles are 
 assigned and compared to be displayed.*/

/* Author: Mark Mckillion, Chris Mowbray
 * Date: 17/04/2012
 * Version 1.0.*/
package assignment4;

import java.awt.*;

@SuppressWarnings("rawtypes")
public class Vehicle implements Comparable
{   //create the images that will be used within the array, images are saved within the 
    //project.
    Image car = Toolkit.getDefaultToolkit().getImage("car-icon.jpg");
    Image boat = Toolkit.getDefaultToolkit().getImage("boat-icon.png");
    Image plane = Toolkit.getDefaultToolkit().getImage("plane-icon.png");
    Image motorbike = Toolkit.getDefaultToolkit().getImage("motorcycle-icon.png");
    Image bicycle = Toolkit.getDefaultToolkit().getImage("bicycle-icon.png");
    Image train = Toolkit.getDefaultToolkit().getImage("train-icon.png");
    Image tank = Toolkit.getDefaultToolkit().getImage("tank-icon.jpg");
    
    //create an array and set it to 0 initially.
    protected static Image [] vehicles = new Image[0];
    
    //create an instance of the class which will be used within the compare to method.
    protected static Vehicle vehicle = new Vehicle();
    
    //create ints that will be used to control the object order and values.
    protected static int num, vehicleValue, compareNum;
    
    //a method that will be used to create an array, will accept an int to determain the 
    //array size.
    public void createArray(int n)
    {   //make the array size equal the number entered.
        vehicles = new Image[n];
        
        //use a for loop to create assign images to the array.
        for(int i = 0; i < vehicles.length; i++)
        {   //create an int to make the array objects random.
            num = (int)(Math.random()*100);
            if(num <= 14)
            {   vehicles[i] = bicycle;
            }   else if(num <= 28)
                {   vehicles[i] = motorbike;
                }   else if(num <= 42)
                    {   vehicles[i] = car;
                    }   else if(num <= 56)
                        {   vehicles[i] = tank;
                        }   else if(num <= 70)
                            {   vehicles[i] = boat;
                            }   else if(num <= 84)
                                {   vehicles[i] = train;
                                }   else if(num >= 85)
                                    {   vehicles[i] = plane;
                                    }
        }
    }
    
    //create a method which will determain how light the vehicle is in comparison to the 
    //others.
    public int getLightNumber(Image c)
    {   //method uses the parameter value to assign an int to each vehicle.
        if(c == bicycle)
        {   vehicleValue = 1;
        }   if(c == motorbike)
            {   vehicleValue = 2;
            }   if(c == car)
                {   vehicleValue = 3;
                }   if(c == tank)
                    {   vehicleValue = 4;
                    }   if(c == train)
                        {   vehicleValue = 5;
                        }   if(c == boat)
                            {   vehicleValue = 6;
                            }   if(c == plane)
                                {   vehicleValue = 7;
                                }
        //return the value.
        return vehicleValue;
    }
    
    //create a method which will determain how fast the vehicle is in comparison to the 
    //others.
    public int getSpeedNumber(Image c)
    {   //method uses the parameter value to assign an int to each vehicle.
        if(c == plane)
        {   vehicleValue = 1;
        }   if(c == train)
            {   vehicleValue = 2;
            }   if(c == boat)
                {   vehicleValue = 3;
                }   if(c == motorbike)
                    {   vehicleValue = 4;
                    }   if(c == car)
                        {   vehicleValue = 5;
                        }   if(c == bicycle)
                            {   vehicleValue = 6;
                            }   if(c == tank)
                                {   vehicleValue = 7;
                                }
        //return the value.
        return vehicleValue;
    }
    
    //create a method which will determain how expensive the vehicle is in comparison to 
    //the other.
    public int getPriceNumber(Image c)
    {   //method uses the parameter value to assign an int to each vehicle.
        if(c == plane)
        {   vehicleValue = 1;
        }   if(c == boat)
            {   vehicleValue = 2;
            }   if(c == tank)
                {   vehicleValue = 3;
                }   if(c == train)
                    {   vehicleValue = 4;
                    }   if(c == car)
                        {   vehicleValue = 5;
                        }   if(c == motorbike)
                            {   vehicleValue = 6;
                            }   if(c == bicycle)
                                {   vehicleValue = 7;
                                }
        //return the value.
        return vehicleValue;
    }
    
    //create a compareTo method that will compare the images that are entered.
    public int compareTo(Image vehicle1, Image vehicle2)
    {   //create to integers that will be used to compare the color numbers.
        int num1, num2;
        
        
        if(ControlPanel.jComboBox4.getSelectedItem().equals("Light to Heavy"))
        {   //if light to heavy is chosen get the values for each colour
            num1 = vehicle.getLightNumber(vehicle1);
            num2 = vehicle.getLightNumber(vehicle2);
            
            //compare the colours and use integers to determain how the colors relate to 
            //each other.
            if(num1 == num2)
            {   compareNum = 0;
            }   if(num1 < num2)
                {   compareNum = -1;
                }   if(num1 > num2)
                    {   compareNum = 1;
                    }
        }
        
        if(ControlPanel.jComboBox4.getSelectedItem().equals("Fast to Slow"))
        {   //if fast to slow is chosen get the values for each colour
            num1 = vehicle.getSpeedNumber(vehicle1);
            num2 = vehicle.getSpeedNumber(vehicle2);
            
            //compare the colours and use integers to determain how the colors relate to 
            //each other.
            if(num1 == num2)
            {   compareNum = 0;
            }   if(num1 < num2)
                {   compareNum = -1;
                }   if(num1 > num2)
                    {   compareNum = 1;
                    }
        }
                
        if(ControlPanel.jComboBox4.getSelectedItem().equals("Expensive to Cheap"))
        {   //if expensive to cheap is chosen get the values for each colour
            num1 = vehicle.getPriceNumber(vehicle1);
            num2 = vehicle.getPriceNumber(vehicle2);
            
            //compare the colours and use integers to determain how the colors relate to 
            //each other.
            if(num1 == num2)
            {   compareNum = 0;
            }   if(num1 < num2)
                {   compareNum = -1;
                }   if(num1 > num2)
                    {   compareNum = 1;
                    }
        }
        //return the comparsion value.
        return compareNum;
    }

    //override all abstract methods.
    @Override
    public int compareTo(Object o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}   //End of Vehicle class.